// 私有化路由
import React from "react";
import { Route, Redirect } from "react-router-dom";
// 引入token 根据token来判断
import { getToken } from "../../utils/sesstion";

// @params component外面传进来的组件 rest外面传进来的属性 --es解构和 ...语法
const PrivateRouter = ({ component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={routeProps => (getToken() ? <Component /> : <Redirect to="/" />)}
    />
  );
};

export default PrivateRouter;
